package com.dmooo.yxmmerchant.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.common.util.SPUtils;
import com.dmooo.yxmmerchant.R;
import com.dmooo.yxmmerchant.common.Config;
import com.dmooo.yxmmerchant.domain.ServiceOrderListBean;
import com.dmooo.yxmmerchant.view.ui.UserInfoActivity;

import java.util.List;

public class MyServiceOrderAdapter extends BaseQuickAdapter<ServiceOrderListBean.Item, BaseViewHolder> {
    public MyServiceOrderAdapter(int layoutResId, @Nullable List<ServiceOrderListBean.Item> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder holder, final ServiceOrderListBean.Item item) {
        holder.setText(R.id.txt_order_num,"单号:"+ item.order_num);
        holder.setText(R.id.txt_time, item.create_time.split(" ")[0]);
//        if ("Y".equals(item.is_own)) {
//            holder.getView(R.id.txt_goods_origin).setVisibility(View.VISIBLE);
//        } else {
//            holder.getView(R.id.txt_goods_origin).setVisibility(View.GONE);
//        }
        holder.getView(R.id.txt_pay).setVisibility(View.GONE);
        holder.getView(R.id.txt_reason).setVisibility(View.GONE);
        holder.getView(R.id.txt_cancle).setVisibility(View.GONE);
        holder.getView(R.id.txt_apply_cancle).setVisibility(View.GONE);
        holder.getView(R.id.txt_ok_shouhuo).setVisibility(View.GONE);
//        holder.getView(R.id.txt_buy_again).setVisibility(View.GONE);
        holder.getView(R.id.txt_comment).setVisibility(View.GONE);
        holder.getView(R.id.txt_danhao).setVisibility(View.GONE);
        holder.getView(R.id.txt_change).setVisibility(View.GONE);
        holder.getView(R.id.txt_wuliu).setVisibility(View.GONE);
        holder.setText(R.id.txt_user_name,"用户:"+item.user_account);
        holder.getView(R.id.txt_user_name).setVisibility(View.VISIBLE);
        if(item.r_phone==null||"".equals(item.r_phone)){
            holder.getView(R.id.txt_user_name2).setVisibility(View.GONE);
        }else{
            holder.getView(R.id.txt_user_name2).setVisibility(View.VISIBLE);
            holder.setText(R.id.txt_user_name2,"中间商:"+item.r_phone);

        }
        if(mContext instanceof UserInfoActivity){
            holder.getView(R.id.ll_ri).setVisibility(View.GONE);
        }else{
            holder.getView(R.id.ll_ri).setVisibility(View.VISIBLE);

        }
        switch (item.status) {
            case "1":
                if (Config.PAY_OFFLINE.equals(item.pay_method)) {
                    holder.setText(R.id.txt_status, "待确认");
                    TextView tx = holder.getView(R.id.txt_reason);
                    tx.setVisibility(View.VISIBLE);
                    tx.setText("订单状态: 公司转账待商家确认收款");
                    tx.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
                    holder.getView(R.id.txt_comment).setVisibility(View.VISIBLE);
                } else {
                    holder.setText(R.id.txt_status, "待支付");
//                    holder.getView(R.id.txt_pay).setVisibility(View.VISIBLE);
                }
                if("1".equals(SPUtils.get(mContext,Config.LOGIN_TYPE,"1").toString())||Config.AUTH.contains("35")||Config.AUTH.contains("36")||Config.AUTH.contains("30"))
                    holder.getView(R.id.txt_change).setVisibility(View.VISIBLE);
                break;
            case "2":
                holder.setText(R.id.txt_status, "待服务");
                TextView tx=holder.getView(R.id.txt_apply_cancle);
                tx.setText("已服务");
                holder.getView(R.id.txt_apply_cancle).setVisibility(View.VISIBLE);
                break;
            case "3":
                holder.setText(R.id.txt_status, "待买家验收");
//                holder.getView(R.id.txt_ok_shouhuo).setVisibility(View.VISIBLE);
//                holder.getView(R.id.txt_wuliu).setVisibility(View.VISIBLE);
//                holder.setText(R.id.txt_reason,"快递单号:"+orderDetailBean.express_number);
                break;
            case "4":
                holder.setText(R.id.txt_status, "待评价");
//                holder.getView(R.id.txt_comment).setVisibility(View.VISIBLE);
//                holder.getView(R.id.txt_buy_again).setVisibility(View.VISIBLE);
                break;
            case "5":
                holder.setText(R.id.txt_status, "已完成");
//                holder.getView(R.id.txt_buy_again).setVisibility(View.VISIBLE);
                break;
            case "6":
                holder.setText(R.id.txt_status, "待审核...");
                holder.getView(R.id.txt_reason).setVisibility(View.VISIBLE);
                holder.setText(R.id.txt_reason, "退款原因: " + item.drawback_reason);
                TextView tx1=holder.getView(R.id.txt_pay);
                tx1.setText("退款审核");
                holder.getView(R.id.txt_pay).setVisibility(View.VISIBLE);
                break;
            case "7":
                holder.setText(R.id.txt_status, "已退款");
                break;
            case "8":
                holder.setText(R.id.txt_status, "拒绝退款");
                holder.getView(R.id.txt_reason).setVisibility(View.VISIBLE);
                holder.setText(R.id.txt_reason, "拒绝原因: " + item.drawback_refuse_reason);
                holder.getView(R.id.txt_apply_cancle).setVisibility(View.VISIBLE);
                break;
        }
        ImageView img = holder.getView(R.id.img_shop);
        Glide.with(mContext).load(Config.APP_INTERFACE_BASE_URL + item.cover).error(R.mipmap.defaultpicture_classify).dontAnimate().into(img);
        holder.setText(R.id.txt_name, item.service_name);
        holder.setText(R.id.txt_num, "共" + item.num + "件  总额:" + Config.RMB + item.allprice);
        holder.setText(R.id.txt_price, Config.RMB + item.price);
        if("Y".equals(item.is_inquiry)){
            holder.setText(R.id.txt_price, Config.RMB+ item.price+"(询价单)");
        }
        holder.setText(R.id.txt_attribute, item.service_time);
        holder.addOnClickListener(R.id.txt_cancle).addOnClickListener(R.id.txt_pay).addOnClickListener(R.id.txt_apply_cancle)
                .addOnClickListener(R.id.txt_ok_shouhuo).addOnClickListener(R.id.txt_change).addOnClickListener(R.id.txt_wuliu).addOnClickListener(R.id.txt_danhao).addOnClickListener(R.id.txt_comment)
        ;
    }
}
